﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HDTuyenChon.BL;

namespace HDTuyenChon.WebControls
{
	public partial class ListPhim : System.Web.UI.UserControl
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			
			
		}	

		protected void TemplateNextPrevious_OnPagerCommand(object sender, DataPagerCommandEventArgs e)
		{
			// Check which LinkButton control raised the event.

			// MaximumRows: The maximum number of records that are displayed 
			// for each page of data.

			// StartRowIndex: The index of the first record that is displayed 
			// on a page of data.

			// TotalRowCount: The total number of records that are available 
			// in the underlying data source.

			switch (e.CommandName)
			{
				// "First" is clicked.
				case "First":
					// In this sample, the maximum number of records on 
					// each page is 10, which is the default page size. 

					// The first page shows the first 10 rows of the data 
					// source, whose row index start from 0.
					e.NewStartRowIndex = 0;
					e.NewMaximumRows = e.Item.Pager.MaximumRows;

					break;

				// "Previous" is clicked.
				case "Previous":
					// The previous page shows the following 10 rows of 
					// the current page. 
					e.NewStartRowIndex = e.Item.Pager.StartRowIndex - e.Item.Pager.PageSize;
					e.NewMaximumRows = e.Item.Pager.MaximumRows;

					break;

				// "Next" is clicked.
				case "Next":
					// The next page shows 10 rows which start from the last 
					// row in current page.
					int iNewIndex = e.Item.Pager.StartRowIndex + e.Item.Pager.PageSize;
					// The new index of the first row to display cannot
					// be bigger than total row count
					if (iNewIndex <= e.TotalRowCount)
					{
						e.NewStartRowIndex = iNewIndex;
						e.NewMaximumRows = e.Item.Pager.MaximumRows;
					}

					break;

				// "Last" is clicked.
				case "Last":
					// The last page shows the last rows of the data source, 
					// which are the remainders after total number is 
					// divided by page size. 
					e.NewStartRowIndex = e.TotalRowCount - e.TotalRowCount % e.Item.Pager.PageSize;
					e.NewMaximumRows = e.Item.Pager.MaximumRows;

					break;
			}
		}

		protected void TemplateGoTo_OnPagerCommand(object sender, DataPagerCommandEventArgs e)
		{
			// Since there is only one Button control, we don't need 
			// to use "switch" or "if".

			// Fetch the new pager number from the TextBox tbPagerNumber.
			int iNewPage = Convert.ToInt32(((TextBox)e.Item.FindControl("tbPageNumber")).Text);

			// Calculate the new index of the first row to display.
			int iNewIndex = e.Item.Pager.PageSize * (iNewPage - 1);

			// The new row index cannot be bigger than total row count
			if (iNewIndex <= e.TotalRowCount)
			{
				e.NewStartRowIndex = iNewIndex;
				e.NewMaximumRows = e.Item.Pager.MaximumRows;
			}
		}

		protected void DataPager1_PreRender(object sender, EventArgs e)
		{
			string loai = Request.QueryString["loaiPhim"];

			PhimBL phimBL = new PhimBL();
			lblTitle.Text = phimBL.GetBlockTitle(loai);
			listPhim.DataSource = phimBL.GetListPhimByLoaiPhim(loai);
			listPhim.DataBind();	
		}
		
	}

	
}